home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2002 January / maximum-cd-2002-01.iso / Files / Mechwarrior 4 Mapping / MW4Editor.exe / content / ABLScripts / GenericScripts / Generic_SentryAlly.abl < prev    next >
Encoding:
Text File  |  2001-07-16  |  6.1 KB  |  209 lines

  1.  
  2. //------------------------------------------------------------------
  3. // NOTE: The fsm name below MUST be changed in order for the
  4. // script to be considered a unique entity!
  5.  
  6. fsm Generic_SentryAlly : integer;
  7.  
  8.  
  9. //------------------------------------------------------------------
  10.  
  11. // Generic_SentryAlly:
  12. //   Stands still.  Move to attack anything that comes within range.
  13. //   Whenever we get within a certain range of a target unit,
  14. //   we follow that unit, and continue to attack any enemies.
  15.  
  16. //------------------------------------------------------------------
  17.  
  18.  
  19.  
  20. //------------------------------------------------------------------
  21. //     Constants
  22. //------------------------------------------------------------------
  23.  
  24.     const
  25.         #include_ <content\ABLScripts\mwconst.abi>
  26.  
  27. //------------------------------------------------------------------
  28. //     Types
  29. //------------------------------------------------------------------
  30.  
  31.     type
  32.         #include_ <content\ABLScripts\mwtype.abi>
  33.     
  34.  
  35. //------------------------------------------------------------------
  36. //     Variables
  37. //------------------------------------------------------------------
  38.  
  39.     var
  40.         static integer            attackRange1;        // At what range do I start shooting?
  41.         static integer            withdrawRange1;        // At what range do I withdraw from combat completely?
  42.  
  43.         static ObjectID            whoToJoin;            // Who do I want to join?
  44.         static integer            joinRange;            // At what range do I join my leader?
  45.         static integer            followXOffset;        // My follow X offset
  46.         static integer            followYOffset;        // My follow Y offset
  47.  
  48.         static integer            attackRange2;        // At what range do I start shooting (after joining)?
  49.         static integer            withdrawRange2;        // At what range do I stop shooting (after joining)?
  50.  
  51.         static integer            piloting;            // Piloting skill
  52.         static integer            gunnery;            // Gunnery skill/chance to hit
  53.         static real                minDelay;            // Minimum amount of time I will wait between shots once a weapon is reloaded
  54.         static real                maxDelay;            // Maximum amount of time I will wait between shots once a weapon is reloaded
  55.         static integer             eliteLevel;            // Elite level.  This helps determine tactics, defensive manuevers, opportunity fire
  56.                                                     // and other things.  It indicates a general level of combat experience.
  57.         static integer            attackThrottle;        // My attack throttle
  58.         static integer            findTypes;            // What kind of enemies to look for
  59.  
  60.          static integer            isShotRadius;        // How far away from me will I detect an enemy shot?
  61.  
  62.         static integer             attackSound;        // The attack sound I play when I first attack
  63.         static integer             deathSound;            // The sound I play when I die
  64.         
  65.         static integer            mood;                // My default mood.
  66.  
  67.         static integer            takeOffDistance;    // My take-off distance if I'm an airplane (ignored if not an airplane)
  68.  
  69. //------------------------------------------------------------------
  70. //     Init: my initialization function
  71. //------------------------------------------------------------------
  72.  
  73. function Init;
  74.     code
  75.         // script-specific variables
  76.         attackRange1    = 500;
  77.         withdrawRange1    = attackRange1 * 3 / 2;
  78.  
  79.         whoToJoin        = NO_UNIT;
  80.         joinRange        = 500;
  81.         followXOffset    = 0;
  82.         followYOffset    = 50;
  83.  
  84.         attackRange2    = attackRange1;
  85.         withdrawRange2    = attackRange2 * 3 / 2;
  86.  
  87.         takeOffDistance    = 150; 
  88.  
  89.         // driver settings
  90.         piloting        = 50;
  91.         gunnery            = 30;
  92.         minDelay        = 1.5;
  93.         maxDelay        = 3.0;
  94.         eliteLevel        = 30;
  95.         attackThrottle    = 80;
  96.         isShotRadius    = 120;
  97.         attackSound        = -1; // no sound
  98.         deathSound        = -1; // no sound
  99.         mood            = NEUTRAL_START;
  100.         findTypes        = FT_DEFAULT;
  101.  
  102. endfunction;
  103.  
  104. //------------------------------------------------------------------
  105. //    StartState: my initial state
  106. //------------------------------------------------------------------
  107.  
  108. state StartState;
  109.  
  110.     code
  111.         SetFiringDelay            (ME,minDelay,maxDelay);
  112.         SetIgnoreFriendlyFire    (ME,true);
  113.         SetIsShotRadius            (ME,isShotRadius);
  114.         SetEntropyMood            (ME,mood);
  115.         SetCurMood                (ME,mood);
  116.         SetSkillLevel            (ME,piloting,gunnery,eliteLevel);
  117.         SetAttackThrottle        (ME,attackThrottle);
  118.  
  119.         if (orderTakeOff(takeOffDistance) == true) then
  120.             trans Wait1State; 
  121.         endif;
  122.  
  123. endstate;
  124.  
  125. //------------------------------------------------------------------
  126. //    Wait1State: wait for something to shoot
  127. //------------------------------------------------------------------
  128.  
  129. state Wait1State;
  130.     code
  131.         OrderMoveLookOut;
  132.  
  133.         if (IsWithin(ME,whoToJoin,joinRange)) then
  134.             trans FollowState;
  135.         endif;
  136.  
  137.         if (FindEnemy(attackRange1,findTypes)) then
  138.             trans Attack1State;
  139.         endif;        
  140. endstate;
  141.  
  142. //------------------------------------------------------------------
  143. //    Attack1State: look for something to shoot
  144. //------------------------------------------------------------------
  145.  
  146. state Attack1State;
  147.     code
  148.         if (LeaveAttackState(withdrawRange1)) then
  149.             OrderStopAttacking;
  150.             SetTarget(ME,NO_UNIT);
  151.             trans Wait1State;
  152.         endif;
  153.  
  154.         if (IsWithin(ME,whoToJoin,joinRange)) then
  155.             trans Attack2State;
  156.         endif;
  157.  
  158.         OrderAttack(true);
  159.  
  160. endstate;
  161.  
  162. //------------------------------------------------------------------
  163. //    FollowState: follow the chosen unit
  164. //------------------------------------------------------------------
  165.  
  166. state FollowState;
  167.     code
  168.         if (FindEnemy(attackRange2,findTypes)) then
  169.             trans Attack2State;
  170.         endif;        
  171.  
  172.         OrderMoveFollow(whoToJoin,followXOffset,followYOffset);
  173.  
  174. endstate;
  175.  
  176. //------------------------------------------------------------------
  177. //    Attack2State: look for something to shoot
  178. //------------------------------------------------------------------
  179.  
  180. state Attack2State;
  181.     code
  182.         if (LeaveAttackState(withdrawRange2)) then
  183.             OrderStopAttacking;
  184.             SetTarget(ME,NO_UNIT);
  185.             trans FollowState;
  186.         endif;
  187.  
  188.         OrderAttack(true);
  189.  
  190. endstate;
  191.  
  192. //------------------------------------------------------------------
  193. //    DeadState: OK, I kicked the bucket.
  194. //------------------------------------------------------------------
  195.  
  196. state DeadState;
  197.     code
  198.         if (deathSound <> -1) then    
  199.             PlaySoundOnce(deathSound);
  200.         endif;        
  201.  
  202.         orderDie;
  203.  
  204. endstate;
  205.  
  206.  
  207. endfsm.
  208.  
  209.